﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Windows.Storage;
using System.IO.IsolatedStorage;

namespace APACWP8.View
{
    public partial class SettingPage : PhoneApplicationPage
    {
        public SettingPage()
        {
            InitializeComponent();
            btnchannel.IsChecked = GetData();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            CheckOrientation(LayoutRoot);
        }
        private void CheckOrientation(Grid content)
        {

            if ((Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
            {
                content.Margin = new Thickness(0, 0, 0, 0);
            }
            else if ((Orientation & PageOrientation.LandscapeLeft) == (PageOrientation.LandscapeLeft))
            {
                content.Margin = new Thickness(0, 0, 36, 0);
            }
            else if ((Orientation & PageOrientation.LandscapeRight) == (PageOrientation.LandscapeRight))
            {
                content.Margin = new Thickness(36, 0, 0, 0);
            }
        }
        public static void SaveData(bool isSave)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("splashToggle"))
                IsolatedStorageSettings.ApplicationSettings.Remove("splashToggle");
            var settings = IsolatedStorageSettings.ApplicationSettings;
            settings.Add("splashToggle", isSave);
            settings.Save();
        }
        public static bool GetRunFist()
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("splashToggle"))
                return true;
            return false;
        }
        public static bool GetData()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            bool token;
            settings.TryGetValue<bool>("splashToggle", out token);
            if (token)
                return token;
            return false;
        }

        private void btntitle_Checkedbtnchannel(object sender, RoutedEventArgs e)
        {
            if(btnchannel.IsChecked==true)
                SaveData(true);
            else
                SaveData(false);
        }
    }
}